<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Works_Entity extends CI_Model
{
    private $tablename = 'works';
    private $id = null;
    private $title = null;
    private $complate = null;
    private $summary = null;
    private $note = null;
    private $order = null;
    private $status = null;
    private $created = null;
    private $changed = null;
    
    public function setId($Id)
    {
        $this->id = $Id;
    }

    public function setTitle($Title)
    {
        $this->title = $Title;
    }

    public function setComplate($Complate)
    {
        $this->complate = $Complate;
    }

    public function setSummary($Summary)
    {
        $this->summary = $Summary;
    }

    public function setNote($Note)
    {
        $this->note = $Note;
    }

    public function setOrder($Order)
    {
        $this->order = $Order;
    }

    public function setStatus($Status)
    {
        $this->status = $Status;
    }

    public function setCreated($Created)
    {
        $this->created = $Created;
    }

    public function setChanged($Changed)
    {
        $this->changed = $Changed;
    }

    public function save()
    {
        $params = array();
        foreach ($this as $key => $val) {
            if ($key == 'tablename') continue;
            if ($val == null || $val == '') continue;
            $params[$key] = $val;
        }
                
        if (!isset($params['id'])) {
            if ($this->db->insert($this->tablename, $params)) {
                return $this->db->insert_id();
            } else {
                return 0;
            }
        } else {
            return $this->db->update($this->tablename, $params, array('id' => $params['id']));
        }
        
    }
    
    public function del($id)
    {
        
        return $this->db->delete($this->tablename, array('id' => $id));    
    }
    
    public function getWorksById($id)
    {
        return $this->db->get_where($this->tablename, array('id' => $id));
    }
    
    public function getAllList()
    {
        return $this->db->get($this->tablename);
    }
    
    public function TotalWorks()
    {
        return $this->db->count_all_results('Works'); 
    } 
}       
        